package zjy.android.radapter.livedata;

import androidx.annotation.NonNull;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.MutableLiveData;

/**
 * @Create zhang
 * @DATE 2021/7/26 0026
 * @DESC
 */
public final class ReturnLiveData<T> {

    private final MutableLiveData<T> valueLiveData = new MutableLiveData<>();
    private final MutableLiveData<Throwable> throwableLiveData = new MutableLiveData<>();

    public void observe(@NonNull LifecycleOwner owner, @NonNull ReturnObserver<? super T> observer) {
        valueLiveData.observe(owner, observer);
        throwableLiveData.observe(owner, observer::onFailure);
    }

    public void postValue(T value) {
        valueLiveData.postValue(value);
    }

    public void postThrowable(Throwable throwable) {
        throwableLiveData.postValue(throwable);
    }
}
